package com.holdtime.jtt809dataservice.client.process;

import com.holdtime.jtt809dataservice.common.event.ClientMessageReceiveEvent;
import com.holdtime.jtt809dataservice.common.process.ClientProtocolProcessor;
import io.netty.channel.ChannelHandlerContext;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import protocol.jtt809.JTT809Packet;
import protocol.jtt809.ProtocolJT809;
import protocol.jtt809.body.DownLinktestReq;
import protocol.jtt809.body.DownLinktestRsp;
import protocol.jtt809.body.RawBody;

/**
 * author: sunwei
 * Date: 2025/3/22 23:30
 * Description:
 */
@Slf4j
@Component
public class ClientDownLinkTestReqProcessor implements ClientProtocolProcessor {
    @Resource
    private ProtocolJT809 protocolJT809;

    @Override
    public int getMsgID() {
        return DownLinktestReq.MSG_ID;
    }

    @Override
    public void process(ClientMessageReceiveEvent event) {
        JTT809Packet<RawBody> source = event.getSource();
        RawBody body = source.getBody();
        ChannelHandlerContext session = event.getChannelHandlerContext();
        log.info("收到上级平台发送的从链路保持请求,jrm:{}", source.getMsgGnsscenterid());
        DownLinktestRsp downLinktestRsp = new DownLinktestRsp();
        JTT809Packet<DownLinktestRsp> packet = protocolJT809.getPacket(downLinktestRsp, DownLinktestRsp.MSG_ID, source.getMsgGnsscenterid());
        session.writeAndFlush(packet);
    }
}
